/****************************************************************************
/@pref:
/Nokia5110 lcd drive
/Write by Crengy Lee
/2011.8.24 at 02:19

Nokia5110 lcd is 48*84 pxils lcd,
*****************************************************************************/
#ifndef _NOKIA5110_LCD_H_
#define	_NOKIA5110_LCD_H_

#include "stm32f10x_gpio.h"
#include "fonts.h"
#include <stdint.h>
#include "os_includes.h"
#include <string.h>

#ifdef __cplusplus
 extern "C" {
#endif
/***
/defin:Define Function set bit
***/

#define FUNCTION_SET_OFFET	((uint8_t)0x20)
#define	FUNCTION_SET_PD		((uint8_t)0x04)
#define	FUNCTION_SET_V		((uint8_t)0x02)
#define	FUNCTION_SET_H		((uint8_t)0x01)

/***
/extended instruction set,must set that H is 0
control (H)
***/
#define	EXT_DISCON_OFFET	((uint8_t)0x08)
#define	EXT_DISCON_D		((uint8_t)0x04)
#define	EXT_DISCON_E		((uint8_t)0x01)

#define	SET_YADDR_OFFET		((uint8_t)0x40)
#define	SET_XADDR_OFFET		((uint8_t)0x80)


#define VCLD_TEMP_OFFET		((uint8_t)0x04)
#define	VCLD_TEMP0		((uint8_t)0x00)
#define	VCLD_TEMP1		((uint8_t)0x01)
#define	VCLD_TEMP2		((uint8_t)0x02)
#define	VCLD_TEMP3		((uint8_t)0x03)

#define	BAIS_SYS_SET		((uint8_t)0x10)
#define	BAIS_SYS_SET1		((uint8_t)0x00)
#define	BAIS_SYS_SET2		((uint8_t)0x01)
#define	BAIS_SYS_SET3		((uint8_t)0x02)
#define	BAIS_SYS_SET4		((uint8_t)0x03)
#define	BAIS_SYS_SET5		((uint8_t)0x04)
#define	BAIS_SYS_SET6		((uint8_t)0x05)
#define	BAIS_SYS_SET7		((uint8_t)0x06)
#define	BAIS_SYS_SET8		((uint8_t)0x07)

/*******
LCD Low Level Hardware Line
There is 5 pin to define(sclk,sdin,reset,sce,dc)
*******/
#define LCD5110_SCLK_PIN                    GPIO_Pin_9
#define LCD5110_GPIO_PORT                   GPIOE
#define LCD5110_GPIO_CLK                    RCC_APB2Periph_GPIOE

#define LCD5110_SDIN_PIN                    GPIO_Pin_10
#define LCD5110_GPIO_PORT                   GPIOE
#define LCD5110_GPIO_CLK                    RCC_APB2Periph_GPIOE

#define LCD5110_RESET_PIN                   GPIO_Pin_12
#define LCD5110_GPIO_PORT                   GPIOE
#define LCD5110_GPIO_CLK                    RCC_APB2Periph_GPIOE

#define LCD5110_SCE_PIN                     GPIO_Pin_13
#define LCD5110_GPIO_PORT                   GPIOE
#define LCD5110_GPIO_CLK                    RCC_APB2Periph_GPIOE

#define LCD5110_DC_PIN                      GPIO_Pin_11
#define LCD5110_GPIO_PORT                   GPIOE
#define LCD5110_GPIO_CLK                    RCC_APB2Periph_GPIOE

#define LCD5110_LEDPWR_PIN                  GPIO_Pin_8
#define LCD5110_GPIO_PORT                   GPIOE
#define LCD5110_GPIO_CLK                    RCC_APB2Periph_GPIOE

void delayms(unsigned  int ii);
void LCD_write_byte(unsigned char dt, unsigned char command);
void LCD_init(void);
void LCD_set_XY(unsigned char X, unsigned char Y);
void LCD_clear(void);
void LCD_write_shu(unsigned char row, unsigned char page,unsigned char c);
void LCD_write_hanzi(unsigned char row, unsigned char page,unsigned char c);
void Nokia5110_GPIO_Init(void);
void  LCD_write_ASCII(uint8_t row,uint8_t page,s8FONT *Ftable, char *ASCIIcha);
void u32tostr(uint32_t dat,char *str);
void LCD_Put_Num(uint8_t row,uint8_t page,uint32_t dat);
INT8U Lcd_FontNum(FontType FontTypeNum);

void Nokia5110_init(void);

#ifdef __cplusplus
}
#endif

#endif /* __Nokia5110_Lcd_H */
